<?php
/**
 * 《我的报价》实现类
 *
 * @author 孙晓晔
 * @version $Id: Quote.class.php 1043 2010-04-01 08:04:38Z sunxy $
 */
require_once(dirname(__FILE__) . '/Quote.class.php');

class QuotePy extends Quote {

	public $orderby = array(
		'-' => '请选择',
		'num' => '套数',
		'urgent' => '紧急程序',
		'date' => '要求日期',
		'1' => '创建时间',
		'2' => '更新时间',
	);

	function __construct() {
		$request['update'] = '$Date: 2009/02/16 07:36:07 $';
		$request['revision'] = '$Revision: 1.1 $';

		parent::__construct($request);
	}

	function pretreat($controller) {
		parent::pretreat($controller);

		$controller->assign_by_ref('urgent_option', $this->urgent);
	}
	
	function tab($controller, $request) {		
		$data = array(
			'我的报价' => array('cc'=>'customer.php?do=QuoteMy.find', 'js'=>''),
			'报价明细' => array('cc'=>'customer.php?do=QuoteItem.find', 'js'=>''),
			'附件信息' => array('cc'=>'customer.php?do=QuoteInfo.find', 'js'=>''),
			
			'我的客户' => array('cc'=>'contact.php?do=CustomerMy.find', 'js'=>''),
			'我的产品' => array('cc'=>'mold.php?do=MoldMy.find', 'js'=>''),
		);
		
		$ret = $this->_tab($data);

		$controller->assign_by_ref('result', $ret);

		$controller->display($request, 'tab');
		return true;
	}

	/**
	 *
	 *
	 * @param Controler $controller
	 * @param array $request
	 */
	function find($controller, $request) {
		$this->pretreat($controller);

		// $controller->assign('t1', strtotime('-1 year'));
		
		$ab = array(
			'-' => '请选择',
			'1' => '格式1',		
			'2' => '格式2',
			'3' => '格式3',
		);
		$controller->assign_by_ref('ab_option', $ab);

		$controller->display($request, 'customer/quote/py/find');
		return true;
	}

	/**
	 *
	 *
	 * @param Controler $controller
	 * @param array $request
	 */
	function findPost($controller, $request) {
		$this->pretreat($controller);

		$this->findPara($controller, $request);

		$db = newdb($this->dsn_r);
		$fmt = "SELECT * FROM %s a %s %s";
		$where = $this->_where($request);
		$orderby = $this->_orderby();
		$sql = sprintf($fmt, $this->tbl, $where, $orderby);
		debug($sql);

		$pager_option = array (
            'db' => $db,
            'sql' => $sql,
            'PageSize' => $this->pagesize,
            'CurrentPageID' => $request['p'],
            'numItems' => $request['n']
		);

		$pager = @new Pager($pager_option);
		$data = $pager->getPageData();

		if ($pager->number > 0) {

			$count = 0;
			$from = $pager->from;
			while ($count < $pager->number) {
				$row = $data[$count];
				$row = $this->_view(null, $row);

				$row['num_'] = $this->_num($row['id']);

				$row = $this->_orderby_x($controller, $row, $this->orderby_s);

				$row['is_delete'] = $this->_is_delete($row);

				$data[$count] = $row;
				$count++;
			}
			$controller->assign_by_ref('result', $data);
			$controller->assign_by_ref('pager', $pager);
		}

		$controller->assign('emp', $_SESSION['id']);
		$controller->assign('empname', $_SESSION['name']);

		$controller->display($request, 'customer/quote/py/list');
		return true;
	}
	
	function ajax_b($controller, $request) {
		$id = $_COOKIE['id_'];
		$ret = array();
	
		if ($this->_ajax_x($id, 'emp')) {
			$ret['status'] = 1;
		} elseif ($this->_ajax_x($id, 'oper')) {
			$ret['status'] = 1;
		} elseif ($this->_audit('71')) {
			$ret['status'] = 1;
		} elseif ($this->_is_admin()) {
			$ret['status'] = 1;
		} else {
			$ret['status'] = 2;
		}
	
		echo json_encode($ret);
	}
}
?>